package me.cloudcat.develop.controller;

import me.cloudcat.develop.dao.UserDao;
import me.cloudcat.develop.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Field;

/**
 * hello world测试
 *
 * @Author: jiafeim12345@163.com
 * @Date: 2018/3/17/017 15:27
 */
@Controller
public class HelloWorldController {

    @Autowired
    UserDao userDao;

    @RequestMapping(value = "/testOne", method = RequestMethod.GET )
    public String testOne(Model model, HttpServletRequest request) {
        return "login";
    }

    @RequestMapping(value = "/testTwo", method = RequestMethod.GET )
    public String testTwo(Model model, HttpServletRequest request) throws IllegalAccessException {
        User user = userDao.findByUsernameOrEmail("zhenzhong");
        Field[] fields = user.getClass().getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            System.out.println(field.getName() + "  " + field.get(user));
        }
        return "login";
    }
}
